package com.sample.app;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean(name = "triangleBean")
@ViewScoped
public class TriangleBean implements Serializable {
    private DroolsHelper droolsHelper = new DroolsHelper();
    private Triangle triangle;

    private String a;
    private String b;
    private String c;

    private List<String> description;

    public Triangle getTriangle() {
        return triangle;
    }

    public void setTriangle(Triangle triangle) {
        this.triangle = triangle;
    }

    public List<String> getDescription() {
        return description;
    }

    public void setDescription(List<String> description) {
        this.description = description;
    }

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }

    public String getC() {
        return c;
    }

    public void setC(String c) {
        this.c = c;
    }

    public void getResult() throws NumberFormatException {
        description = null;
        triangle = droolsHelper.initializeTriangle(Integer.valueOf(a), Integer.valueOf(b), Integer.valueOf(c));
        if (triangle.getError() == null) {
            description = new ArrayList<>();
            for (TriangleType triangleType : triangle.getDescription()) {
                description.add(triangleType.toString());
            }
        }
    }

    public void cleanTriangle() {
        triangle = null;
    }

}
